package hikari.objects3d.light;

import com.gooddies.wiring.Wiring;
import hikari.managers.EngineProperties;
import hikari.managers.Manager3D;
import hikari.math.CircleDrawer;
import hikari.utils.Utils;
import org.swig.jirr.E_LIGHT_TYPE;
import org.swig.jirr.ISceneManager;
import org.swig.jirr.ITexture;
import org.swig.jirr.IVideoDriver;
import org.swig.jirr.vector3df;

/**
 * @author Dmitry
 */
public class OmniLight3dObject extends Light3dObject {

    private static ITexture billboardTexture;
    private CircleDrawer circle1 = null;
    private CircleDrawer circle2 = null;
    private CircleDrawer circle3 = null;
    private int optimizationFrameNumber = 0;

    public OmniLight3dObject(ISceneManager sceneManager) {
        super(sceneManager, E_LIGHT_TYPE.ELT_POINT, "OmniLight");
    }

    @Override
    public void drawGizmos() {
        IVideoDriver driver = Wiring.getComponent(Manager3D.class).getVideoDriver();
        driver.resetTransformMatrix();
        driver.setMaterial(Wiring.getComponent(EngineProperties.class).getSMaterialProperty("lightGizmoMaterialFront"));
        vector3df rotation = new vector3df(getRotation());
        if (optimizationFrameNumber % 10 == 0) {
            circle1 = new CircleDrawer(20, getPosition(), rotation.rotationToDirection(), getLightNode().getRadius());
            circle2 = new CircleDrawer(20, getPosition(), rotation.addX(90).rotationToDirection(), getLightNode().getRadius());
            circle3 = new CircleDrawer(20, getPosition(), rotation.addZ(90).rotationToDirection(), getLightNode().getRadius());
        }
        optimizationFrameNumber++;

        if (circle1 != null) {
            circle1.drawCircle();
            circle2.drawCircle();
            circle3.drawCircle();
        }

    }

    @Override
    public String objectType() {
        return "omniLight";
    }

    @Override
    protected ITexture getBillboardTexture() {
        if (billboardTexture == null) {
            billboardTexture = Wiring.getComponent(Utils.class).loadTextureFromResource("icons/omniLight.png");
        }
        return billboardTexture;
    }
}
